package com.aaa.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author 荆豪峰
 * @version 1.0
 */
@Component
@Aspect
public class TransactionAop {
    @Pointcut("execution(* com.aaa.impl.*.*(..))")
    private void transationAdvice(){
    }

    @Before("transationAdvice()")
          public void before(){
         System.out.println("前置通知---开启事务");
         }
    @After("transationAdvice()")
    public void after(){
        //理解为方法执行完
        System.out.println("后置通知--提交事务");
    }

    @AfterReturning("transationAdvice()")
    public void afterReturning(){
        System.out.println("后置返回通知");
    }

    @AfterThrowing("transationAdvice()")
    public void afterThrowing(){
        System.out.println("异常通知--事务回滚");
    }

    @Around("transationAdvice()")
    public void arount(ProceedingJoinPoint joinPoint){
        System.out.println("环绕通知-前");
        try {
            joinPoint.proceed();//回调连接点方法
            System.out.println("方法执行完毕");
        } catch (Throwable throwable) {
            System.out.println("环绕通知-异常");
        }finally {
            System.out.println("环绕通知-最终");
        }
    }
}
